Usage of Float and Integer in DynaActionForm properties and retrieving them with struts-html.tld tags - forms

I have a DynaActionForm element in my struts-config.xml like:
<form-bean name="myActionForm" type="org.apache.struts.action.DynaActionForm">
<!-- Control Params -->
<form-property name="action" type="java.lang.String" />
<form-property name="list" type="java.lang.String" initial="master_document_list.data"/>
<!-- Business params -->
<form-property name="code" type="java.lang.String"/>
<form-property name="name" type="java.lang.String"/>
<form-property name="description" type="java.lang.String"/>
<form-property name="sequenceNumber" type="java.lang.Float"/>
</form-bean>
And the jsp page where I am trying to use it:
<!-- struts-html.tld imported with prefix html -->
<html:form>
<table>
<tr>
<td>Sequence No.</td>
<td><html:text property="sequenceNumber" maxlength="15" style="width:75%"/></td>
</tr>
<table>
</html:form>
but when i do this I am getting a JspException saying "No getter method for property sequenceNumber. I am quite sure that the name is correct. Is it the type that is not getting accepted then? I thought the DynaActionForm allowed types are all major java types including the Thread-Safe Wrappers (e.g. Float, Integer, Short, Long, etc.).
N.B. I am using struts1

After digging apache documentation, i figured out that
<html:text> tag has got the following settings:
name= Name of the form bean
property= Name of the property associated to the form-property tag for the bean above
Althernatively, using ${myBean.map.myProp} will point me to the right direction.
Thanks all,

Related

uploading multiple images from the frontend using FAL in TYPO3 /extbase

I am using this Helhum example for uploading images from the frontend, which is located on the following link
https://github.com/helhum/upload_example
If we check its form fields in partial file on location
https://github.com/helhum/upload_example/blob/master/Resources/Private/Partials/Example/FormFields.html
there is given two uploads option which are following
{namespace h=Helhum\UploadExample\ViewHelpers}
<label for="title">
<f:translate key="tx_uploadexample_domain_model_example.title" /> <span class="required">(required)</span>
</label><br />
<f:form.textfield property="title" /><br />
<label for="image">
<f:translate key="tx_uploadexample_domain_model_example.image" />
</label><br />
<h:form.upload property="image" >
<f:if condition="{resource}">
<f:image image="{resource}" alt="" width="50"/>
</f:if>
</h:form.upload><br />
<label for="image_collection">
<f:translate key="tx_uploadexample_domain_model_example.image_collection" />
</label><br />
Here for the property="imageCollection.0" if I make it multiple="multiple" then it give me the following error
1297759968: Exception while property mapping at property path "imageCollection": PHP Warning: spl_object_hash() expects parameter 1
to be object, null given in
/var/www/webroot/typo3_src-7.6.14/typo3/sysext/extbase/Classes/Persistence/ObjectStorage.php line 155 (More information)
And if I remove the 0 and just try to click a botton then it even not generate a form and give me the following error
1297759968: Exception while property mapping at property path "": The source is not of type string, array, float, integer or boolean, but of
type "object" (More information)
So long story in short, how can I fix this example for multiple images uploading. I try to used without helper function just used a standerd fluid function <f:form:upload> it still give me a same error. please somebody can help me in sort out this problem.

Create a popup inside a form

I want to include a popup inside a form. The normal way to do that is to have 2 forms like:
<div class="wrapper" >
<h:form>
<h:panelGroup id="id1" layout="block">
<ui:include src= content1 />
</h:panelGroup>
</h:form>
</div>
<h:form id="modalId">
<ui:include src= popupContent >
</ui:include>
</h:form>
and render with a button inside content1, the form "modalId" that contains the popUp.
I have the popup form in an external component that is included inside "content1". Due to the popup form is inside the other form,it isnt well rendered. How can I fix that? The idea is to use that component that is common for all my xhtml views
The way i was writing my own components was to rely on the existance of the external form. That is, i did not include any form elements inside the component.
If there was a need to reference the outer form element then i would just pass the from id as one of the attributes of the interface. Composite components are really useful for this kind of stuff:
<composite:interface>
<composite:attribute name="formId" type="java.lang.String" />
</composite:interface>
<composite:implementation>
<h:commandButton value="button" action="someaction">
<f:ajax execute="#{cc.attrs.formId}" render="#{cc.attrs.formId}" />
</h:commandButton>
</composite:implementation>
Then you include that in your outer form (assuming 'comp' is your namespace for composite components and 'modal' is the name of the file containing the component):
<h:form id="myForm">
<comp:modal formId="myForm"/>
</h:form>
Go through this tutorial if you are not familiar with them:
http://docs.oracle.com/javaee/6/tutorial/doc/giqzr.html

Custom tag with variables

I am trying to use custom tag with variables.
for eg)
<c:forEach var="test" items="itemstest">
${test}
</c:forEach>
In the above code i am able to access the test value inside the <c:forEach> tag.
I need to create a custom tag with similar functionality.
I have got info from the oracle docs http://docs.oracle.com/javaee/5/tutorial/doc/bnamu.html under title Declaring Tag Variables for Tag Handlers.
Can anyone pls help me to implement the same with example.
Hi i have solved it in the following way
class: test.java
public void doTag() throws JspException, IOException {
getJspContext().getOut().flush();
//any method or operation
super.doTag();
getJspContext().setAttribute(variable, "Hello");
}
Create getter setter for variable
tld file:
<tag>
<name>test</name>
<tag-class>com.org.test</tag-class>
<body-content>empty</body-content>
<attribute>
<name>inputValue</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>variable</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
jsp file:
<%# taglib uri="/WEB-INF/tld/tldfilename.tld" prefix="tag" %>
<tag:test inputValue="hello" variable="testValue"/>
${testValue}
For something so simple, you may be better off using tag files, which makes it easy to create a tag library using some small additions to the normal jsp syntax (and is part of the standard)
http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html
A "tag with variables" is done using an attribute declaration, JSP code is quite simple:
<%#tag pageEncoding="utf-8" %>
<%-- dont forget to add declaration for JSTL here -->
<%#attribute name="test" type="java.lang.String" required="true" %>
<c:forEach var="test" items="itemstest">
${test}
</c:forEach>
See the linked documentation on whre to put and name the files to make them accessible within you own jsp files.

Multiple Form elements pointing to a single path in Spring

I did a bit of searching, and it doesn't appear that this specific question has been asked (if I am mistaken, I apologize).
The application I'm working on processes reports on a set of data, and the reports are separated by client and the report category.
The issue I have is that the number of clients and categories varies for each job, so I need to dynamically generate the following form elements based on the requirements for each job.
<!-- CLIENT NAME -->
Inclusion Client Name:
<form:errors path="clientName" cssClass="error"/><br />
<form:input path="clientName" />
<br /><br />
<!-- REPORTING CCATEGORIES -->
Reporting Categories:
<form:errors path="reportingCategories" cssClass="error"/><br />
<form:input path="reportingCategories" />
<br /><br />
<!-- comma separated list of categories -->
In the process of testing some theories, I learned that you can point multiple form elements to the same path, and Spring will concatenate the values into a comma separated list. My only concern is the order in which these form elements are read.
<!-- CLIENT NAME A -->
Inclusion Client Name:
<form:errors path="clientName" cssClass="error"/><br />
<form:input path="clientName" />
<br /><br />
<!-- REPORTING CATEGORIES A -->
Reporting Categories:
<form:errors path="reportingCategories" cssClass="error"/><br />
<form:input path="reportingCategories" />
<br /><br />
<!-- comma separated list of categories -->
<!-- CLIENT NAME B -->
Inclusion Client Name:
<form:errors path="clientName" cssClass="error"/><br />
<form:input path="clientName" />
<br /><br />
<!-- REPORTING CATEGORIES B -->
Reporting Categories:
<form:errors path="reportingCategories" cssClass="error"/><br />
<form:input path="reportingCategories" />
<br /><br />
<!-- comma separated list of categories -->
In the second code snippet above, my test case reads CLIENT NAME A before CLIENT NAME B (Essentially working down the page from top to bottom). Will this always be the case?
Yes, the order will always be the order in which the form fields are defined in the form.
When defining multiple fields with the same path, you also can bind them as an array in your request method like:
#Controller
public class YourController {
#RequestMapping(....)
public String foo(#RequestParam String clientName[], #RequestParam String reportingCategories[], BindingResult result) {
...
}
}

Why the form id prefix in the h:message output?

I'm currently trying simple validation using required="true"
<h:form>
<h:messages globalOnly="true"/>
<h:panelGrid>
<h:panelGrid columns="3">
<f:facet name="header">
Login Application Sample
</f:facet>
<h:outputLabel for="UserId" value="User Id" />
<h:inputText id="UserId" value="#{userBean.userId}" required="true" />
<h:message for="UserId"/>
<h:outputLabel for="Password" value="Password" />
<h:inputSecret id="Password" value="#{userBean.password}" required="true" />
<h:message for="Password" />
<f:facet name="footer">
<h:commandButton value="Login" action="#{userBean.login}"/>
<h:commandButton type="reset" value="Reset"/>
</f:facet>
</h:panelGrid>
</h:panelGrid>
</h:form>
Leaving the fields blank, and then clickin on the login button, these error messages will display on the right side of each field :
j_idt7:UserId: Validation Error: Value is required.
j_idt7:Password: Validation Error: Value is required.
This is what I expected, but I don't want to display the form id prefix of 'j_idt7:'. I read book examples, they don't output the form id prefix. What I want is :
UserId: Validation Error: Value is required.
Password: Validation Error: Value is required.
What should I do to skip displaying the form id prefix in the component specific messages ?
I'm currently testing JSF 2 in glassfish v3.
The message label defaults to component's client ID, exactly the one as you can see in generated HTML output via rightclick, View Source. That j_id7 is in this particular case the client ID of the parent <form> element. If you give the JSF component a fixed ID like <h:form id="login"> then the labels will become login:UserId and login:Password respectively.
You can however use the input component's label attribute to override it altogether so that the message label will be shown exactly as you intented.
<h:inputText ... label="User ID" />
<h:inputSecret ... label="Password" />
If the input component's label attribute is present, then it will be used instead of the client ID. Using prependId="false" as suggested by other answers has disadvantages. Don't do that.
A completely different alternative is to use requiredMessage (or converterMessage or validatorMessage) attribute for this, but this doesn't allow parameterizing messages and thus you'd have to hardcode the labels and such.
<h:inputText ... label="User ID is required." />
<h:inputSecret ... label="Password is required." />
See also:
Change the default message "Validation Error: Value is required" to just "Value is required"
Getting the component id on the error validation message
How to parameterize requiredMessage attribute in composite component?
Noted should be that it's indeed awkward to have labels duplicated like this:
<h:outputLabel for="userId" value="User ID" ... />
<h:inputText id="userId" ... label="User ID" />
<h:outputLabel for="password" value="Password" ... />
<h:inputSecret id="password" ... label="Password" />
If you happen to use JSF utility library OmniFaces, then you can use <o:outputLabel> to let JSF transparently set the label attribute of the associated component:
<o:outputLabel for="userId" value="User ID" ... />
<h:inputText id="userId" ... />
<o:outputLabel for="password" value="Password" ... />
<h:inputSecret id="password" ... />
If you use MyFaces and the bean validation framework (JSR303) try to define a MessageBundle with a key javax.faces.validator.BeanValidator.MESSAGE
faces-config.xml
<application>
<message-bundle>ApplicationMessages</message-bundle>
</application>
ApplicationMessages.properties
#javax.faces.validator.BeanValidator.MESSAGE={1}: {0}
javax.faces.validator.BeanValidator.MESSAGE={0}
Details
You need to override these messages from JSF.
You can have a messages.properties file in your classpath
Messages.properties
javax.faces.component.UIInput.REQUIRED=Field must be entered.
Faces-config.xml
<application>
<message-bundle>Messages</message-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
Have a look at this Article
If you care to see the HTML source from your browser, you will find out that the id of your input field is <form-id>+":"+<input-field-id>, in your case, j_idt7:UserId:. Try to give your <h:form> some meaningful id in order to make some sense out of it. You can read about JSF IDs here. In case you don't like it, you can turn it off by modifying your form tag to something like this,
<h:form prependId = false> // its true by default.
But that might turn out to be problematic, as pointed out by BalusC here.
Furthermore, it seems like you have never configured any validation messages yourself. Which in turn ends up with this message. Hence, a message.properties file is needed to have a control over message and show something more appropriate. Even then the field name should not be the part of the message, to make those validation message generic to avoid repetition. See BalusC's answer regarding the use of label attribute inside the <h:inputText>.
Where you are writing required = true, there you can define requiredMessage = "My Message" for any input type.
e.g.
<h:inputText autocomplete="false" id = "CellNumber" label="Cell Number" required="true" requiredMessage="Cell Number Required" maxlength="10" value="#{userManagedBean.cellNumber}" >