I am working on a display table version 1.2 on Struts 2 application. I am having problem with fetching value for "titleKey" in my diplay table column.
<display:column titleKey="title.key" >
I am kinda sure that I do not have configuration problem. I tried fetching the same value outside the table as :
<s:text name="title.key"/>
I am successful in doing that.
What could be the issue?
I don't know of any reason why DisplayTag would know about the S2 I18N mechanisms.
Either use DisplayTag's I18N support or by not using keys (e.g., the "title" attribute) and using values exposed by normal S2 mechanisms.
Related
In my application I have a dropdown list in the form, I want to take one value of that dropdown list from User and store it in the database. I am new to spring development and I do not know what is the datatype of the dropdown list in MySql and plus how should I configure the controller and entity class?
I have used ENUM in MySql database.
`domain` enum('Web-Development', 'Software Development','Application Development') DEFAULT NULL,
You can follow this approach followed for Dropdown:
1] Create a lookup table where you define all your consatnts with their associated type and id something like as said in this link :
Look up table.
2] Your Drop-down will display these values from lookup table as soon as a value is selected in drop down their associated id will be used in backend to store the selected value can be used to store in database rather than actual values as this id should be unique and be used for DB CRUD operations.
this might help, I have solved the issue for tempory base or for small scale development. All I have done is, I have changed datatype in MySql from ENUM to VARCHAR(45). (ENUM also works fine). And then I have manually added the dropdown values in the controller class.
#ModelAttribute("domainList")
public List<String> getCountryList() {
List<String> domainList = new ArrayList<String>();
domainList.add("Web-Development");
domainList.add("Software Development");
domainList.add("Application Development");
return domainList;
}
In my JSP file, I have called this under <form:select>, <form:option>, and <form:options>
<td>
<form:select path="domain">
<form:option value="NONE" label="Select" />
<form:options items="${domainList}" />
</form:select>
</td>
For, Data binding in Entity class I have just used return type as String and generate getters, setters and toString.
That's all I have done, it is working. Happy Coding...
I am using Spring 3.0.6 and their tag library. I am using the form:checkbox tag. From what I read and researched, it is supposed to create a hidden field with the same name and a leading _ character. This tells spring whether the checkbox was checked or not so that it will properly set my model attribute when the checkbox is not checked or when it is disabled.
The problem is that I am not seeing a hidden field created for my form:checkbox. I thought it might be my version of Spring, but I saw another post where a developer appeared to be using Spring 3.0.5 and it was generating the hidden field for him.
Here is a code snippet from my JSP where I create the checkbox.
<form:checkbox path="contactInformation.optOutOfProgram" value="Y" id="chkOptOutOfProgram" disabled="true" />
Here is the resulting HTML that is generated:
<input id="chkOptOutOfProgram" name="contactInformation.optOutOfProgram" disabled="disabled" type="checkbox" value="Y"/>
There is no hidden field with the name _contactInformation.optOutOfProgram generated on the page. I read that I could manually code this but I also read it is supposed to automatically create the hidden field.
I found the issue when looking at the Tutorials that Braj pointed out even though the Tutorial does no explicitly explain this. One of the things that is different from my code and the code in the tutorials as well as all of the other code that I saw in my research is that I have disabled="true" in my form:checkbox declaration. I disable it using jQuery based on stuff entered by the user in other fields. Apparently if you set the field using the disabled attribute for the form:checkbox Spring tag, it does not generate the hidden field. As soon as I removed that from form:checkbox, the generated html content had the hidden field.
I guess I need to report that as a possible bug to the Spring developers.
I have been using JSTL to fetch values from my database and display it in my jsp page using a similar code as shown below.
<sql:setDataSource
var="myDS"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb"
user="root" password="secret"
/>
<sql:query var="list_users" dataSource="${myDS}">
SELECT * FROM users;
</sql:query>
<c:forEach var="user" items="${listUsers.rows}">
<c:out value="${user.name}" />
<c:out value="${user.email}" />
<c:out value="${user.profession}" />
</c:forEach>
My team leader advised me that it is not a good practice to put queries in the jsp page directly. Since there is a database name and username and password in this code I'm not sure if this code implements proper security. I would like to know your thoughts on the matter, and if there is any alternative to do this using JSTL itself.
Since JSTL is executed on server side, there's no security hole because the query cannot be seen by clients of the application. There are other problems with this approach:
The query is not reusable. If you need it in other pages, you will need to repeat the query. When you have simple queries like this one you cannot check the problem, but this arises with more complex statements that needs parameters as well.
You're creating a connection manually per page! This will slow your application. Use a proper datasource for a database connection pool configured as a resource or programatically (C3PO or BoneCP, for example)
Move all your database code into proper Data Access Layer classes. And use <sql> for JSTL for learning purposes only, not for real world applications.
More info:
How to use JSTL sql tag
Retrieve values from JDBC and use JSTL tags to call the methods
Should a database connection stay open all the time or only be opened when needed?
You should really do your query in your java class, not in the jsp, like your team leader advised.
On the security side it doesn't really matter, all the code is available on the server, jsp or java. The sql tag shouldn't output that information in the generated page.
But really the question is more about the right use of the technologies:
jsp is used as a template, it should take data and show them to the end user. Some basic operation can be done life looping on data list or formating data, but this should be only specific to the view you want to make
java controler is used to recuperate data and configure the view as needed like which jsp to use and which data to send in that jsp
Thanks in advance for taking the time to read!
I'm working on a web application on the NetBeans IDE 7.1, with Struts 1.3.10, Apache Tomcat 7.0.22, PostgreSQL 9.1 on Windows 7.
My question is the following:
I have a class called "Reminder", it's properties are: startDate, endDate and id. I want to get all the start and end dates from all the reminders in my jsp so I can highlight this range of days on a calendar at a sidebar of my web application.
In my login action I have the following code:
Reminder reminder = new Reminder();
ArrayList<Reminder> queryResults =
dbms.queryReminders(reminder);
Here I've gathered all the reminders from the database (The model function simply does a SELECT * from reminders and returns that)
Then I finish with:
request.setAttribute("reminders",queryResults);
return mapping.findForward(User);
Here I've set the collected results to an attribute I decided to call "reminders", this should have all the reminders I want.
Afterwards I get the data from view like this:
<bean:write name="reminders" scope="request"/>
But all I get is something like: [classes.Reminder#1d1ce11] (In this case, I have only inserted one reminder in the database. Also I have a class called Reminder in my package called classes, so I think it's referring to an object of class Reminder (the one I inserted on the DB)).
But what I want to do is to be able to obtain the startDate and endDate from that object, not just the object like that. Does anybody know how to access these properties from the jsp?
I've done a lot of research but usually what tutorials show you is a way to get the properties of classes with these bean tags, but here I have an array of objects of a certain class and I want their properties, so things are different.
I would really appreciate some guidance. Thank you!
That's because you stored a List (of type ArrayList) to the request on the following code:
request.setAttribute("reminders",queryResults);
So, in order to get each Reminder from the List, you will need to iterate through the list (in the JSP).
To iterate through a collection, you will use <logic:iterate> tag:
<logic:iterate name="reminders" id="reminder" scope="request">
ID: <bean:write name="reminder" property="id" />
Start Date: <bean:write name="reminder" property="startDate" />
End Date: <bean:write name="reminder" property="endDate" />
</logic:iterate>
I'm having some problems with Icefaces 1.82 (we cannot use any later version than this...) and a datatable with a rowselector.
I found this thread and it seems that I have the exact same problem (which should be fixed for Icefaces 1.7..):
RowSelector 'rendered' attribute is
working with a single value for the
whole dataTable, but if I want to have
dynamically a different value for each
independent row, the behavior is not
as expected.
<!-- List of articles -->
<ice:dataTable styleClass="dataTable" value="#{bb.pms}" id="articles" var="articlePm"
rendered="#{bb.notEmptySearchResult}">
<h:column>
<ice:rowSelector rendered="#{articlePm.allowedEdit}"
id="selected" value="#{articlePm.selected}"
selectionListener="#{bb.rowSelectionListener}"
preStyleOnSelection="true"
mouseOverClass="pointer"/>
Problem: The the rowSelector 'rendered' does not work for single rows.
Does anyone have a solution for my problem?