JSF: Backing Beans with nested objects? - java

JSF 1.1, using a backing bean with a nested objects inside I can read all properties of the nested object.
For example assuming a backing bean named "foo" with a nested object "bar" can I set/write via h:form all the properties of foo.bar?
I mean something like this:
f:view
h:form
h:inputText value="#{myBean.mySelectedReport.someProp}" /
and this in the backing bean:
public SomeObject getMySelectedReport() {...}
but when I sent it to the correct backing bean it doesn't store the value of the someProp value

Nice, I can answer by myself as I solved by myself:
if useful for others having the same problem the problem is the JSF 1.1 wildcard on "from-view-id", for example "/ajax/uiChannel*" match only pages without any query params into the "from url",
only this one "/ajax/uiChannel.jsp?*" and "/ajax/uiChannel*?*" wildcard seems to work

Related

How to Bind a Bean Argument Using a List in JDBI 3

I'm trying to use the SqlObject API to store a list of Bean POJOs in Postgres. My interface looks like this:
#UseClasspathSqlLocator
#RegisterBeanMapper(SomeBean.class)
public interface LeadStateDao {
#SqlUpdate
#GetGeneratedKeys
SomeBean update(#BindBean SomeBean bean);
#SqlUpdate
#GetGeneratedKeys
SomeBean upsert(#BindBean SomeBean bean);
#SqlUpdate
#GetGeneratedKeys
int[] batchUpsert(#BindList List<SomeBean> beans);
}
I'm compiling with parameters which is why I don't have the argument explicitly named (this is working fine). The update and upsert methods work as expected, thanks to #RegisterBeanMapper. However the batchUpsert doesn't, and I get:
java.lang.UnsupportedOperationException: No argument factory registered for 'com.foo.SomeBean#49d11f58' of type class com.foo.SomeBean
Is there a way to bind a bean as an argument, as part of a list, without having to write a custom argument factory? The docs are frustratingly vague here:
java.util.Collection and Java arrays (stored as SQL arrays). Some additional setup may be required depending on the type of array element.
Not sure what "some additional setup" entails.
I never used #BindList like this (for bulk operations) and I don't know if it is made to be used with beans.
As the docs say:
Binding a list of values is done through the #BindList annotation. This will expand the list in a 'a,b,c,d,…​' form. Note that this annotation requires you to use the <binding> notation, unlike #Bind (which uses :binding)
So if you have
#BindList List<Long> data
as parameter in the interface you will have to use
select * from my_data where id in (<data>)
as query (note the brackets instead of the colon). I doubt that you can use it with beans at all!

How can I put a bean object to sessionMap, and then retrieve its properties on jsp page using Struts 2 property tag

In login Action I am checking user authentication, and if it is validated, I am putting the user bean into sessionMap:
public String execute()
{
if(userValid)
sessionMap.put("userBean", userBean); //userBean retrieved from DB
}
Now on the landing jsp, when trying to retrieve the session items:
<s:property value="#session.userBean.name" />
Obviously this would return an Object type, as I am storing it that way, so how can I type caste this to UserBean class.
I was expecting to get a solution for this on Google, but found it nowhere since this seems to be a basic implementation. So please let me know if there is any other way to implement this functionality using Struts2.
This works fine for me...
<sp:property value="#session.usertype"/>
<sp:property value="#session.bean.loginID"/>
This both worked fine for me...
sessionMap.put("bean", loginBean);
sessionMap.put("usertype", loginBean.getUserType());
I declared something like this....
Just make sure that in property tag you you same name you used while setting the bean in sessionMap ....
This should probably work....
Obviously you can't cast it to UserBean class if the object is not the instance of that class. In the value attribute you have put a string "#session.userBean.name". Struts parse this string for OGNL expression and if it's a valid expression that returns a value, it will replace it with that value. The returned type is Object, but this type is determined by ValueStack implementation.
Then property tag writes this object to the out. It uses toString() to convert the object to string. And if your object implements this method, then this value would be written.
Looks like your expression returns an Object, which has instance type String, so it's already implemented this method.

XPages/JSF: Date value binding to managed bean reads but doesn't write

I have created a little XPage search form with a backing bean. This works great with strings, everything is bound using Expression Language and I can access the value in my bean to compose the actual search string.
However, this doesn't seem to be working for dates. I have a date field that looks like this:
<xp:inputText
themeId="Field.Date"
id="inputStartDate" value="#{Search.calStart}">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
My bean has a very basic getter/setter for this:
public Date getCalStart() {
return calStart;
}
public void setCalStart(Date calStart) {
this.calStart = calStart;
}
The problem is that while the field will populate from the backing bean, the bean is not affected by the field. So if in my constructor I set a date field to 7/18/2014, it looks fine on my page. But if I pick a date on the page and perform a refresh, the value does not change in the bean. The dates remain null or whatever I've initialized them to in the bean.
Is there something about the converter (other than handling it as a Java Date in my bean, which I'm doing) that breaks the value binding?
I have had this problem with Date and Beans before but not in Xpages.
What I did was to circumvent the getter/setter with my own and within those convert to the format I want.

Jasper Report: Store in variable value of parameter bean property

I've a little issue to propose.
I've defined in Spring a bean named EnvParam. I've passed this bean in my report processed by Jasper, using an hashmap of parameters.
In Jasper XML I've mapped my bean with import tag in this way:
<import value="Mypath.EnvParam" />
After that I want to point my bean properties in GUI elements.
So, I've defined in Jasper some variables in this way:
varDummy = $P{EnvParam}.myProperty
so in my GUI element I've that link $V{varDummy}.
When I run my application my report doesn't show the correct value of property, setting NULL in my GUI.
But if I put in my GUI object my property $P{EnvParam}.myProperty without using of variable the value will show correctly.
I've resolved my issue, changing the procession time of variable, put the value as "REPORT"
The default the value has set on "NOW" (I think - in italian, version used the value named "ADESSO")

SEAM Entity Query on field of sub object

Using seam-gen based code. I have an object "Classroom", which contains an instance of "Location". I want to query for classrooms but specifying a value on the Location object.
Something like 'select from Classroom where Location.State = "NY"'. When I try to bind a selectOneMenu with a list of states to #{ClassroomList.classroom.location.state} I'm getting errors.
Was getting a null pointer exception on Location. I'm assuming I need to instantiate a new "Location" on the Classroom object, but not sure where to do that. On the Classroom entity's constructor? On the ClassroomList backing bean (where the example object is bound to the ClassroomList JSP search fields)?
Yes, you need to instantiate ClassroomList.instance.Location. Because the ClassroomList.instance is not bound to the Database, this is not done automagically
Not sure if this is the best way, but I got it working.
I have a String exposed on my ClassroomList backing bean as "String locationState". My dropdown list of states binds to that
Then that's referenced in my restrictions as:
...
lower(classroom.location.state) like lower(concat(#{classroomList.locationState}, '%'))",
...
--
When I tried to instantiate ClassroomList.instance.Location, I would get:
javax.servlet.ServletException with message: "Id and clazz must not be null"
Not sure what's causing that?

Categories

Resources