placeholder attribute in combobox,textbox,doublebox in zk - placeholder

how to add contents in placeholder like static with dynamic contents.
e.g.:
<doublebox maxlength="10"
mandatory="#load(something.valueRequired)"
width="250px"
tooltiptext="Enter Number"
value="#bind(something.infoNumericValue)"
placeholder="#load(something.infoData);">
</doublebox>
So, please tell me how to add
enter with dynamic content(#load(something.infoData))
and it is shown like "enter your something" in placeholder.

You can use EL expressions for this:-
placeholder="Enter ${something.infoData}"
anything you write in EL expression needs to be loaded previously into zul.So make sure your something is already loaded

Found this gem buried in the ZK MVVM EL documentation.
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
...
<doublebox placeholder="#load(c:cat('enter your ',something.infoData))"/>
First we load in the core ZK tag library, then we can use the cat function to concatenate your static text with your dynamically loaded text.

EL (${}) and MVVM (#) expressions cannot be mixed with text literals. So, the even following don't work:
<label value="Literal ${expression}"/>
<label value="Literal #load(data)"/>
As the whole thing is not an expression, ZK interprets none of it as an expression and it is just text. Note I'm using a label here to make the point, but this applies to anywhere you use these expressions, including in the placeholder.
My recommendation would be to move this back into your view model:
<doublebox placeholder="#load(vm.placeholder)"/>
...
public MyViewModel {
private Something something;
public String getPlaceholder() {
return "Enter a " + something.getInfoData();
}
}

Answer given By
khcyt's profile
<zk> <zscript>
class A
{
public A(String s, Long v, Boolean is_group) { s_= s; v_= v; is_group_= is_group; }
public String getLabel() { return s_; }
public void setLabel(String s) { s_=s; }
public Boolean isGroup() { return is_group_; }
public Long getValue() { return v_; }
public String getPlaceholder() { return "Please type some text"; }
String s_= null;
Long v_= null;
Boolean is_group_= null;
}
lm.add(new A("Today", 1L, Boolean.TRUE));
lm.add(new A("RE: Bandbox Autocomplete Problem", 2L, Boolean.FALSE));
lm.add(new A("", 3L, Boolean.FALSE));
lm.add(new A("RE: FileUpload", 4L, Boolean.FALSE));
lm.add(new A("", 5L, Boolean.FALSE));
lm.add(new A("Yesterday", 10L, Boolean.TRUE));
lm.add(new A("", 11L, Boolean.FALSE));
lm.add(new A("RE: SelectedItemConverter Question' ite", 12L, Boolean.FALSE));
lm.add(new A("Last week", 100L, Boolean.TRUE));
lm.add(new A("RE: Times_Series Chart help", 101L, Boolean.FALSE));
lm.add(new A("", 102L, Boolean.FALSE));
class VM
{
public ListModel getListModel() { return lm; }
}
]]></zscript>
<window id="win" title="Window ZK6 dynamic template" border="normal" width="600px"
apply="org.zkoss.bind.BindComposer" viewModel="#id('vm') #init('VM')" >
<listbox model="#bind(vm.listModel) #template(each.isGroup() ? 'group_model' : 'item_model')">
<listhead>
<listheader hflex="3" label="Column 1"/>
<listheader hflex="1" label="Column 2"/>
</listhead>
<template name="group_model">
<listgroup open="true" label="#load(each.label)"/>
</template>
<template name="item_model">
<listitem vflex="1">
<listcell>
<textbox hflex="1" placeholder="#init(each.placeholder)" value="#bind(each.label)"/>
</listcell>
<listcell>
<label value="#load(each.value)"/>
</listcell>
</listitem>
</template>
</listbox>
</window>
</zk>

Related

Update TextBox bound to DataGrid

I hope I can explain my problem properly.
I have a datagrid bound to an ObservableCollection object, and a TextBox bound to the selected item of my datagrid.
When I programmatically modify the SelectedItem property value (Name), my TextBox text value is not updated !
here is my design code:
<DataGrid Name="grid" HorizontalAlignment="Left" Margin="119,28,0,0" VerticalAlignment="Top" Height="237" Width="200" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="nom" Binding="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataGrid.Columns>
</DataGrid>
<TextBox Name="textbox" Text="{Binding ElementName=grid, Path=SelectedItem.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="18" Margin="119,276,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="200"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="392,54,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
and here is my Code Behind:
ObservableCollection<Element> obs;
class Element
{
public string Name { get; set; }
public Element(string name) { Name = name; }
}
public MainWindow()
{
InitializeComponent();
obs = new ObservableCollection<Element>() { new Element("element2"), new Element("element2"), new Element("element3")};
grid.ItemsSource = obs;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var sel = grid.SelectedItem as Element;
sel.Name = "something";
grid.Items.Refresh(); //this updates the selected element to "something" but does nothing to the textbox
}
Problem solved.
I had to fire PropertyChanged event whenever a modification is made to the model.
here my new code:
class Element : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Name"));
}
}
public Element(string name) { Name = name; }
}

Variable cannot be resolved error in struts2

My requirement is am trying to populate pid(projectid) from project table and name from userdetails table as an drop down for a form.Am new to struts framework. Could someone please throw us some light on this issue please.
Here is the code:
sprintform.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link href="css/jquery.ui.datepicker.css" rel="stylesheet"
type="text/css" />
<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.17.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){$('.dateTxt').datepicker({
dateFormat : 'yy-mm-dd'
}); });
</script>
</head>
<body>
<h1 style="color: green">Sprint</h1>
<s:form action="sprintInsert" namespace="/" method="post"
name="sprintForm" theme="xhtml">
<s:textfield name="title:" size="40" maxlength="40" required="true"
label="Title" />
<p>
Begin Date: <input id="one" class="dateTxt" type="text"
name="begindate" />
</p>
<p>
End Date: <input id="two" class="dateTxt" type="text" name="enddate" />
</p>
<s:select label="ProjectId" headerKey="-1"
headerValue="Select Project Id" list="projectidList" name="pid" />
<%-- <s:select label="Owner" headerKey="-1"
headerValue="Select Sprint Owner" list="sprintownerList"
name="sprintowner" /> --%>
<tr>
<td>State:</td>
<td><select name="state">
<option value="">Choose a state..</option>
<option value="A">Active</option>
<option value="F">Future</option>
<option value="C">Close</option>
</select></td>
</tr>
<s:textfield name="targetestimatedpoints" size="40" maxlength="40"
required="true" label="Target Estimate pts:" />
<s:textfield name="totalestimatedpoints" size="40" maxlength="40"
required="true" label="Total Estimate pts:" />
<s:textfield name="totaldefaultestimatedhours" size="40"
maxlength="40" required="true" label="Total Detail Estimate Hrs: " />
<s:textfield name="todohours:" size="40" maxlength="40"
required="true" label="Total To Do Hrs:" />
<s:textfield name="description: :" size="40" maxlength="40"
required="true" label="Description: " />
<tr align="right">
<td><div align="center">
<input type="submit" value="save">
</div>
<td align="center"><input type="reset" value="Reset"></td>
</tr>
</s:form>
<s:if test="hasActionErrors()">
<div id="fieldErrors">
<s:actionerror />
</div>
</s:if>
</body>
</html>
SprintAction.java:
package com.bits.sprintanalyzer.action;
import java.util.List;
import org.apache.log4j.Logger;
import com.bits.sprintanalyzer.ResourceException;
import com.bits.sprintanalyzer.dao.SprintDAO;
import com.opensymphony.xwork2.ActionSupport;
public class SprintAction extends ActionSupport {
private static final Logger LOG = Logger.getLogger(SprintAction.class);
/**
*
*/
private static final long serialVersionUID = -6257623073537028210L;
private String title;
private String begindate;
private String enddate;
private String pid;
private String sprintowner;
private String state;
private int targetestimatedpoints;
private int totalestimatedpoints;
private int totaldefaultestimatedhours;
private int todohours;
private String description;
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public String getSprintowner() {
return sprintowner;
}
public void setSprintowner(String sprintowner) {
this.sprintowner = sprintowner;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getTargetestimatedpoints() {
return targetestimatedpoints;
}
public void setTargetestimatedpoints(int targetestimatedpoints) {
this.targetestimatedpoints = targetestimatedpoints;
}
public int getTotalestimatedpoints() {
return totalestimatedpoints;
}
public void setTotalestimatedpoints(int totalestimatedpoints) {
this.totalestimatedpoints = totalestimatedpoints;
}
public int getTotaldefaultestimatedhours() {
return totaldefaultestimatedhours;
}
public void setTotaldefaultestimatedhours(int totaldefaultestimatedhours) {
this.totaldefaultestimatedhours = totaldefaultestimatedhours;
}
public int getTodohours() {
return todohours;
}
public void setTodohours(int todohours) {
this.todohours = todohours;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String display() throws Exception {
return INPUT;
}
public String getBegindate() {
return begindate;
}
public void setBegindate(String begindate) {
this.begindate = begindate;
}
public String getEnddate() {
return enddate;
}
public void setEnddate(String enddate) {
this.enddate = enddate;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getpidList() throws ResourceException {
return SprintDAO.getpidList();
}
public List<String> getOwnerList() throws ResourceException {
return SprintDAO.getOwnerList();
}
#Override
public void validate() {
}
#Override
public String execute() throws Exception {
LOG.info("title" + title);
LOG.info("begindate" + begindate);
LOG.info("enddate" + enddate);
LOG.info("pid" + pid);
LOG.info("sprintowner" + sprintowner);
LOG.info("state" + state);
LOG.info("targetestimatedpoints" + targetestimatedpoints);
LOG.info("totalestimatedpoints" + totalestimatedpoints);
LOG.info("totaldefaultestimatedhours" + totaldefaultestimatedhours);
LOG.info("todohours" + todohours);
LOG.info("description" + description);
// ProjectDAO.insert(projectname,description,scrummaster,productowner,begindate,enddate);
int i = SprintDAO.save(this);
if (i > 0) {
return "success";
}
return "error";
}
}
SprintDAO:
package com.bits.sprintanalyzer.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.bits.sprintanalyzer.ResourceException;
import com.bits.sprintanalyzer.action.SprintAction;
import com.bits.sprintanalyzer.util.ConnectionUtil;
public class SprintDAO {
private static final String PROJECTQUERY = "select pid from project";
private static final String USERQUERY = "select name from userdetail";
public static List<String> getpidList() throws ResourceException{
List<String> projectidList = new ArrayList<String>();
// this should be populated from DB
try (Connection con = ConnectionUtil.INSTANCE.getConnection();
PreparedStatement st = con.prepareStatement(PROJECTQUERY)){
ResultSet rs =st.executeQuery();
while(rs.next()){
projectidList.add(rs.getString(1));
}
return projectidList;
}
catch (SQLException | ResourceException e) {
throw new ResourceException("Failed to validate project id", e);
}
}
public static List<String> getOwnerList() throws ResourceException{
List<String> sprintownerList = new ArrayList<String>();
// this should be populated from DB
try (Connection con = ConnectionUtil.INSTANCE.getConnection();
PreparedStatement st = con.prepareStatement(USERQUERY)){
ResultSet rs =st.executeQuery();
while(rs.next()){
sprintownerList.add(rs.getString(1));
}
return sprintownerList;
}
catch (SQLException | ResourceException e) {
throw new ResourceException("Failed to validate productowner", e);
}
}
//insert into database
public static int save(SprintAction SA) throws Exception{
int status=0;
try{
Connection con = ConnectionUtil.INSTANCE.getConnection();
PreparedStatement ps = con.prepareStatement("insert into sprint(pid,title,begindate,enddate,owner,state,targetestimatedpoints,totalestimatedpoints,totaldefaultestimatedhours,todohours,description) values(?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1, SA.getPid());
ps.setString(2, SA.getTitle());
ps.setString(3, SA.getBegindate());
ps.setString(4, SA.getEnddate());
ps.setString(5, SA.getSprintowner());
ps.setString(6, SA.getState());
ps.setInt(7, SA.getTargetestimatedpoints());
ps.setInt(8, SA.getTotalestimatedpoints());
ps.setInt(9, SA.getTotaldefaultestimatedhours());
ps.setInt(10, SA.getTodohours());
ps.setString(11, SA.getDescription());
status=ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();}
return status;
}
}
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"/WEB-INF/classes/struts-2.1.7.dtd">
<struts>
<!--
You could also set the constants in the struts.properties file
placed in the same directory as struts.xml
-->
<constant name="struts.devMode" value="true" />
<package name="sprintanalyzer" extends="struts-default" namespace="/">
<!--
If no class attribute is specified the framework will assume success and
render the result index.jsp
If no name value for the result node is specified the success value is the default
-->
<action name="">
<result>/jsp/login.jsp</result>
</action>
<!--
If the URL is hello.action then call the execute method of class HelloWorldAction.
If the result returned by the execute method is success render the HelloWorld.jsp
-->
<action name="login" class="com.bits.sprintanalyzer.action.LoginAction"
method="execute">
<result name="success">/jsp/sprintanalyzer.jsp</result>
<result name="input">/jsp/login.jsp</result>
</action>
<action name="projectform" class="com.bits.sprintanalyzer.action.ProjectAction"
method="display">
<result name="input">/jsp/projectform.jsp</result>
</action>
<action name="projectInsert" class="com.bits.sprintanalyzer.action.ProjectAction"
method="execute">
<result name="success">/jsp/sprintanalyzer.jsp</result>
</action>
<action name="sprintform" class="com.bits.sprintanalyzer.action.SprintAction"
method="display">
<result name="input">/jsp/sprintform.jsp</result>
</action>
<action name="sprintInsert" class="com.bits.sprintanalyzer.action.SprintAction"
method="execute">
<result name="success">/jsp/sprintanalyzer.jsp</result>
</action>
</package>
</struts>
Issue is coming from both projectidlist and sprintownerList. Please advise accordingly.
Please find below stacktrace:
2016-10-01T18:23:38.916+0530|Info: 2016-10-01 18:23:38,916 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The first TextProvider in the ValueStack (com.opensymphony.xwork2.ActionSupport) could not locate the message resource with key 'Login'
2016-10-01T18:23:38.917+0530|Info: 2016-10-01 18:23:38,917 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The default value expression 'Login' was evaluated and did not match a property. The literal value 'Login' will be used.
2016-10-01T18:23:38.925+0530|Info: 2016-10-01 18:23:38,924 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The first TextProvider in the ValueStack (com.opensymphony.xwork2.ActionSupport) could not locate the message resource with key 'Login'
2016-10-01T18:23:38.925+0530|Info: 2016-10-01 18:23:38,925 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The default value expression 'Login' was evaluated and did not match a property. The literal value 'Login' will be used.
2016-10-01T18:23:57.121+0530|Info: 2016-10-01 18:23:57,120 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The first TextProvider in the ValueStack (com.opensymphony.xwork2.ActionSupport) could not locate the message resource with key 'Login'
2016-10-01T18:23:57.121+0530|Info: 2016-10-01 18:23:57,121 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The default value expression 'Login' was evaluated and did not match a property. The literal value 'Login' will be used.
2016-10-01T18:23:57.128+0530|Info: 2016-10-01 18:23:57,128 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The first TextProvider in the ValueStack (com.opensymphony.xwork2.ActionSupport) could not locate the message resource with key 'Login'
2016-10-01T18:23:57.129+0530|Info: 2016-10-01 18:23:57,128 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The default value expression 'Login' was evaluated and did not match a property. The literal value 'Login' will be used.
2016-10-01T18:24:03.841+0530|Severe: Sat Oct 01 18:24:03 IST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2016-10-01T18:24:04.022+0530|Info: 2016-10-01 18:24:04,021 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The first TextProvider in the ValueStack (com.bits.sprintanalyzer.action.LoginAction) could not locate the message resource with key 'welcome to Sprint Analyzer Tool'
2016-10-01T18:24:04.022+0530|Info: 2016-10-01 18:24:04,022 WARN org.apache.struts2.util.TextProviderHelper.warn:45 - The default value expression 'welcome to Sprint Analyzer Tool' was evaluated and did not match a property. The literal value 'welcome to Sprint Analyzer Tool' will be used.
2016-10-01T18:24:06.835+0530|Warning: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'pid': The requested list key 'projectidList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:237)
at org.apache.struts2.components.Component.findValue(Component.java:358)
at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:856)
at org.apache.struts2.components.UIBean.end(UIBean.java:510)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.jsp.sprintform_jsp._jspx_meth_s_select_0(sprintform_jsp.java:236)
at org.apache.jsp.jsp.sprintform_jsp._jspx_meth_s_form_0(sprintform_jsp.java:144)
at org.apache.jsp.jsp.sprintform_jsp._jspService(sprintform_jsp.java:88)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptorcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
2016-10-01T18:24:06.844+0530|Warning: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'pid': The requested list key 'projectidList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:237)
at org.apache.struts2.components.Component.findValue(Component.java:358)
at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at
Here is the login code:
package com.bits.sprintanalyzer.action;
import org.apache.log4j.Logger;
import com.bits.sprintanalyzer.ResourceException;
import com.bits.sprintanalyzer.dao.LoginDAO;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
private static final Logger LOG = Logger.getLogger(LoginAction.class);
/**
*
*/
private static final long serialVersionUID = 6877145894906143530L;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
#Override
public void validate(){
if (username==null || username.length()==0 || password ==null || password.length() ==0 )
addActionError(getText("User name or Password cannot be null"));
}
#Override
public String execute() throws Exception {
try{
if( LoginDAO.isValidUser(username, password) ){
return SUCCESS;
}
else
{
addActionError(getText("Invalid Username or Password"));
}
}catch(ResourceException e){
LOG.error("Failed to valid User", e);
addActionError(getText("Something Went wrong with DBConnection"));
}
return INPUT;
}
}
Latest stacktrace after changing connection string:
2016-10-01T18:55:04.396+0530|Warning: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list', name 'pid': The requested list key 'projectidList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:237)
at org.apache.struts2.components.Component.findValue(Component.java:358)
at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:856)
at org.apache.struts2.components.UIBean.end(UIBean.java:510)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at va:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
1) You have MySQL connection exception as below:
Establishing SSL connection without server's identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
To resolve this use the connection string like below:(change the db name to your existing db name)
jdbc:mysql://localhost:3306/dbname?autoReconnect=true&useSSL=false
This needs to be sorted first, that's why the values of the variables are not been rendered
2) In the Latest trace the requested list key 'projectidList' could not be resolved as a collection/array/map/enumeration/iterator type.
This error occurs when you try to access a list/collection which haven't been created.
Try to initialize the collection objects List<String> projectidList at class level.
when particular action is triggered at that time, JSP page is not knowing the the type of field, in this case, when you write List<String> projectidList = new ArrayList<String>(); instead of this, change it to ArrayList projectidList = new ArrayList();.
Make sure that you access list after the action class is instantiated i.e. corresponding action is called.
If you want to directly access it before calling action make it static and access it inside jsp.

OneMenu not persisting changed value

After my post (Hibernate Primefaces AutoComplete text) I switched the implementation a little. But now I am facing a problem.
Even if I use an AJAX event I do not keep the selected value saved to populate a second drop down.
my CREATE.XHTML
<h:head></h:head>
<ui:debug rendered="true"/>
<body>
<h:form id="createAddressForm" prependId="true">
<!-- <p:messages autoUpdate="true" /> -->
<p:growl id="msgs" showDetail="true" />
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="countryDropDown" value="Country" />
<p:selectOneMenu id="countryDropDown" value="#{addressController.selectedIsoCountry}" >
<p:ajax listener="#{addressController.onCountryChange}" update="stateDropDown" />
<f:selectItem itemValue="" itemLabel="Select a country"/>
<f:selectItems value="#{addressController.countryMap}" />
</p:selectOneMenu>
<p:outputLabel for="stateDropDown" value="State" />
<p:selectOneMenu id="stateDropDown" value="#{addressController.state}" >
<f:selectItem itemValue="" itemLabel="Selecione a State" />
<f:selectItems value="#{addressController.stateMap}" />
</p:selectOneMenu>
</h:panelGrid>
</h:form>
</body>
</html>
And this is AddressController.java
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
import br.com.azulseguros.ejb.CountryEJB;
import br.com.azulseguros.entity.Country;
import br.com.azulseguros.entity.State;
#SessionScoped
#Named
public class AddressController {
#EJB
private CountryEJB countryEJB;
private String selectedIsoCountry = null;
private State state = null;
private Map<String, String> countryMap = null;
private Map<String, String> stateMap = null;
#PostConstruct
private void init() {
Map<String, String> retorno = new TreeMap<String, String>();
for (Country _tmp : countryEJB.findAll()) {
retorno.put(_tmp.getName(), _tmp.getIso());
}
countryMap = retorno;
}
public Map<String, String> getCountryMap() {
return countryMap;
}
public Map<String, String> getStateMap() {
return stateMap;
}
public String getSelectedIsoCountry() {
return selectedIsoCountry;
}
public State getState() {
return state;
}
public void setSelectedIsoCountry(String selectedIsoCountry) {
this.selectedIsoCountry = selectedIsoCountry;
}
public void setState(State state) {
this.state = state;
}
public void setCountryMap(Map<String, String> countryMap) {
this.countryMap = countryMap;
}
public void setStateMap(Map<String, String> stateMap) {
this.stateMap = stateMap;
}
public void onCountryChange() {
setStateMap(getStatesFromSelectedCountry());
}
private Map<String, String> getStatesFromSelectedCountry() {
Map<String, String> retorno = new TreeMap<String, String>();
if (selectedIsoCountry != null && !selectedIsoCountry.equals("")) {
for (State _tmp : countryEJB.findByIso(selectedIsoCountry).getStates()) {
retorno.put(_tmp.getName(), _tmp.getFu());
}
}
return retorno;
}
}
The EJB responsibile for finding all countries and states is working fine. There is a lot of issues with that and I do not know what to do to fix it.
1 - After I invoke the page for the first time it calls the init method 10 times;
2 - After that it evoked the method getStatesFromSelectedCountry even not choosing any country from the 1st drop down and after that evokes the init method again;
3 - When i choose a country it evokes 7 times the init method and then the getStatesFromSelectedCountry() but the selectedIsoCountry is null.
The bean's init method is invoked many times because you have defined the bean both as a CDI bean using javax.inject.Named, without scope, and as a JSF Managed Bean using javax.faces.bean.SessionScoped; if you intended to use CDI beans, simply replace the latter annotation with javax.enterprise.context.SessionScoped. See Why are there different bean management annotations
From a CDI point of view, the bean is by default RequestScoped, this should explain also the second issue you are experiencing.
Concerning the third issue, see this Q/A:
Why is the getter called so many times by the rendered attribute?
Why JSF calls getters multiple times

Failing to set a default value to the composite component

I have a List<String> and I successfully represent it in a datatable; now I am trying to create a composite component out of it, but it seems I keep having trouble understanding how StateHelper does work.
What I want to do is, if the value attribute passed by xhtml evaluates to null, to create a new List<String> automatically. Right now, the only possible action is clicking a button that adds a new item to the list.
My component
<cc:interface componentType="testComponent">
<cc:attribute name="value" required="true" type="java.util.List"/>
</cc:interface>
<cc:implementation>
<f:event type="postAddToView" listener="#{cc.init}" />
<p:dataTable id="data" value="#{cc.data}" var="_data">
<p:column headerText="Nombre / Relación">
<h:outputText value="#{_data}" />
</p:column>
</p:dataTable>
<p:commandButton value="Añadir" process="#this" update="data"
actionListener="#{cc.addData}" ajax="true"/>
</cc:implementation>
The component bean is
#FacesComponent("testComponent")
public class TestComponent extends UIOutput implements NamingContainer {
private static final String LISTA_DATOS = "LST_DATOS";
private static final Logger log = Logger.getLogger(TestComponent.class.getName());
#Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
public List<String> getData() {
#SuppressWarnings("unchecked")
List<String> data = (List<String>) this.getStateHelper().get(LISTA_DATOS);
return data;
}
public void setData(List<String> data) {
this.getStateHelper().put(LISTA_DATOS, data);
}
public void addData() {
List<String> data = (List<String>)this.getData();
data.add("HOLA");
this.setData(data);
}
public void init() {
log.info("En init()");
if (this.getStateHelper().get(LISTA_DATOS) == null) {
if (this.getValue() == null) {
this.getStateHelper().put(LISTA_DATOS, new ArrayList<String>());
} else {
this.getStateHelper().put(LISTA_DATOS, this.getValue());
}
}
}
The component is called like that
<h:form>
<imas:editorTest value="#{testBean.data1}"/>
</h:form>
<h:form>
<imas:editorTest value="#{testBean.data2}"/>
</h:form>
with testBean being:
private List<String> data1 = new ArrayList<>(Arrays.asList("ONE", "TWO", "SIXTYNINE"));
private List<String> data2 = null;
public List<String> getData1() {
return this.data1;
}
public void setData1(List<String> data1) {
this.data1 = data1;
}
public List<String> getData2() {
return this.data2;
}
public void setData2(List<String> data2) {
this.data2 = data2;
}
The issue I found is that, when passing data2 (the null list), clicking the button adds a new item but only the first two times; after that, no matter how many times I click the button, no new items are added to the list (no exception shown in the log). On the opposite, there is no problem adding as many items as I wish to the component initialized with data1.
One thing that I have observed and that leads me to thinking that I am misusing getStateHelper is that, when I click the button, the init() method is executed twice and, at that time, this.getStateHelper().get(LISTA_DATOS) is null, while I expected it to be not null due to having initialized it when the component was first rendered. I expected getStateHelper to carry such state between invocations, where am I wrong?.
Oh! I am using Wildfly 8.1 (no upgrades) with JDK 7.
Digging deeper, I found some evidence of a bug, so I reported it. I'll update the answer to see if it is really a bug or some big misconception from me.

Update "Simple" Listbox ZK

I want to update the listbox when submit button is clicked. the listbox initially consists of a list of JSONObject, after submit button clicked, the list elements changed and the listbox should update with the change but I can't do this. can you help me upadate the listbox?
this is how I put the list of JSONObject in the listbox
<listbox id="userListbox">
<listhead>
<listheader label="Id"></listheader>
<listheader label="Name"></listheader>
<listheader label="Address"></listheader>
<listheader label="Phone"></listheader>
</listhead>
<listitem forEach="${userController.list}">
<listcell label="${each.id}" ></listcell>
<listcell label="${each.name}" ></listcell>
<listcell label="${each.address}" ></listcell>
<listcell label="${each.phone}" ></listcell>
</listitem>
in class UserController:
private List<JSONObject> list;
#Listen("onClick = #submitButton")
public void onSubmit(Event event) {
loadUser();
}
private void loadUser() {
JSONObject input = new JSONObject();
input.put("name", nameBox.getText());
list = getUserList(input);
}
public List<JSONObject> getList() {
return list;
}
public void setList(List<JSONObject> list) {
this.list = list;
}
and I don't know how to update the listbox? thank you for your help.
in class UserController:
private List<JSONObject> list;
Listbox userListbox;
#Listen("onClick = #submitButton")
public void onSubmit(Event event) {
loadUser();
}
private void loadUser() {
JSONObject input = new JSONObject();
input.put("name", nameBox.getText());
list = getUserList(input);
userListbox.setModel(list);
userListbox.set//Your own item renderer
}
public List<JSONObject> getList() {
return list;
}
public void setList(List<JSONObject> list) {
this.list = list;
}
and I don't know how to update the listbox? thank you for your help.

Resources