Pass input text value to bean method without binding input value to bean property

Bind the component as UIInput to the view and use UIInput#getValue() to pass its value as method argument. <h:inputText binding=”#{input1}” /> <h:commandButton value=”Test” action=”#{myBean.execute(input1.value)}” /> with public void execute(String value) { // … } Note that the value is this way already converted and validated the usual JSF way. See also: How does the ‘binding’ … Read more

Should Rails helpers assume an instance variable exists or should they receive them as parameters?

Receive them as a param. Otherwise, as the app grows, it gets very difficult to trace where the instance vars are being set when refactoring, troubleshooting, etc. Also, I believe there’s a general best practice to only use instance vars in views within the initial template…and from there you should pass the var into helpers … Read more

Count how many arguments passed as positional

You can create a decorator, like this: def checkargs(func): def inner(*args, **kwargs): if ‘y’ in kwargs: print(‘y passed with its keyword!’) else: print(‘y passed positionally.’) result = func(*args, **kwargs) return result return inner >>> @checkargs …: def foo(x, y): …: return x + y >>> foo(2, 3) y passed positionally. 5 >>> foo(2, y=3) y … Read more

How can we force naming of parameters when calling a function?

In Python 3 – Yes, you can specify * in the argument list. From docs: Parameters after “*” or “*identifier” are keyword-only parameters and may only be passed used keyword arguments. >>> def foo(pos, *, forcenamed): … print(pos, forcenamed) … >>> foo(pos=10, forcenamed=20) 10 20 >>> foo(10, forcenamed=20) 10 20 >>> foo(10, 20) Traceback (most … Read more

What do ** (double star/asterisk) and * (star/asterisk) mean in a function call?

A single star * unpacks a sequence or collection into positional arguments. Suppose we have def add(a, b): return a + b values = (1, 2) Using the * unpacking operator, we can write s = add(*values), which will be equivalent to writing s = add(1, 2). The double star ** does the same thing … Read more

How to pass props to Screen component with a tab navigator?

you can use the property ‘children’ to pass an element type jsx like instead of the property ‘component’, is recomended from react-native. On this way you can pass props to component example: <tab.Screen name=”home” children={()=><ComponentName propName={propValue}/>} /> is neccesary to use ‘()=>’ because the property children need a function that return a jsx element, it’s … Read more

Why do we need to specify the column size when passing a 2D array as a parameter?

When it comes to describing parameters, arrays always decay into pointers to their first element. When you pass an array declared as int Array[3] to the function void foo(int array[]), it decays into a pointer to the beginning of the array i.e. int *Array;. Btw, you can describe a parameter as int array[3] or int … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)