It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Pagination is not working in ehour1.2 when i click on next page. Here is the link
http://www.ehour.nl/forum/viewtopic.php?f=2&t=40529#p41972
Pagination is not working in ehour1.2 when i click on next page. Here is the link
http://www.ehour.nl/forum/viewtopic.php?f=2&t=40529#p41972
Here is my java code:
public class TreeReportDataPanel extends Panel {
private static final long serialVersionUID = -6757047600645464803L;
private static final AttributeModifier CSS_ALIGN_RIGHT = AttributeModifier.replace("style", "text-align: right;");
private final ReportConfig reportConfig;
public TreeReportDataPanel(String id,
TreeReportModel reportModel,
ReportConfig reportConfig,
final ExcelReport excelReport
) {
super(id);
this.reportConfig = reportConfig;
Border blueBorder = new BlueTabRoundedBorder("blueFrame");
add(blueBorder);
blueBorder.setOutputMarkupId(true);
if (excelReport != null) {
blueBorder.add(new ExcelLink("excelLink", reportModel.getReportCriteria()) {
#Override
protected ExcelReport createReportBuilder() {
return excelReport;
}
});
} else {
blueBorder.add(HtmlUtil.getInvisibleLink("excelLink"));
}
blueBorder.add(getReportHeaderLabel("reportHeader", reportModel.getReportRange(), EhourWebSession.getSession().getEhourConfig()));
addHeaderColumns(blueBorder);
addReportData(reportModel, blueBorder);
addGrandTotal(reportModel, blueBorder);
}
#SuppressWarnings("unchecked")
private void addReportData(TreeReportModel reportModel, WebMarkupContainer parent) {
List<TreeReportElement> elements = (List<TreeReportElement>) reportModel.getReportData().getReportElements();
DataView<TreeReportElement> dataView = new TreeReportDataView("reportData", new TreeReportDataProvider(elements));
dataView.setOutputMarkupId(true);
dataView.setItemsPerPage(20);
parent.add(new HoverPagingNavigator("navigator", dataView));
parent.add(dataView);
}
public class HoverPagingNavigator extends AjaxPagingNavigator {
private static final long serialVersionUID = 1095553728045877576L;
private final IPageable pageable;
public HoverPagingNavigator(String id, IPageable pageable) {
super(id, pageable);
this.pageable = pageable;
}
#Override
public boolean isVisible() {
return pageable.getPageCount() > 1;
}
}
My html looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<div style="width:100%;text-align: right;height:22px"><a wicket:id="excelLink"
title="Export to Excel"><img src="img/download.png" border="0"/></a></div>
<table class="reportTable" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th wicket:id="columnHeaders"></th>
</tr>
</thead>
<tfoot>
<tr class="totalRow">
<td wicket:id="cell" valign="top"><b>2,140</b></td>
</tr>
</tfoot>
<tbody>
<tr class="dataRow" wicket:id="reportData">
<td wicket:id="cell" valign="top"></td>
</tr>
</tbody>
</table>
<span wicket:id="navigator">[dataview navigator]</span>
</div>
</div>
</div>
i think blueFrame_body is the generated one, i can't set the setOutputMarkupId property set to true. I always get the following error message:
Caused by: java.lang.IllegalArgumentException: cannot update component that does not have setOutputMarkupId property set to true. Component: [BorderBodyContainer [Component id = blueFrame_body]]
From your stack : cannot update component that does not have setOutputMarkupId property set to true -> Component: blueFrame_body. It is hard to tell if this is the only reason but try this:
blueFrame_body.setOutputMarkupId(true);
Related
I have read hundreds of posts about this problem and I still can't find a solution.
Please help with this horrible mistery;
I would like to have different default values in my DropDownListFor. The "PartialViewList1 exists out of 4 items.
I want the DropDownListFor to select the id of the current item. (item.id)
But because of testing purposes I just filled in "3". And even that doesn't work.
The Models are filled correctly, I am able to add more code of the controller but that wouldn't add much. But please ask if you want me to.
And yes I know that it is better to make the SelectList in the controller, but first I want to make it work.
View:
#foreach (var item in Model.PartialViewList1)
{
<tr>
<td>Plaats: </td>
<td>#item.PlaceNumber</td>
<td>
#Html.DropDownListFor(x => x.PartialView.Id, new SelectList(Model.PartialViewList2, "Id", "Name", 3),
new { onchange = "this.form.submit();" })</td>
</tr>
}
Screen shot of the users view
I hope that maybe someone can use this for his or her problem.
With Stephen Mueke I have found the solution. The problem is that if "x => x.PartialView.Id" already has a value then the default value : "3" will be overriden by the Id.
And you can't generate multiple DropDownlistFor's while binding them to the same property.
My solution on my problem:
View:
#using (Html.BeginForm("_PartialSettingsDropDownList1", "Home")){
<table>
#for (int i = 0; i < Model.maxNumberOfViews; i++)
{
<tr>
<td>
Plaats #(i+1)
</td>
<td>
#Html.DropDownListFor(x => Model.PartialViewList[i].ID, new SelectList(Model.PartialViewList, "Id", "Name", Model.PartialViewList[i].ID), "select")
</td>
</tr>
}
</table>
#Html.HiddenFor(x => x.maxNumberOfViews)
<input class="submit" type="submit" value="Submit" />}
Controller:
[HttpGet]
public PartialViewResult _PartialSettingsDropDownList1()
{
PartialScreenViewModel viewModel = new PartialScreenViewModel();
viewModel.PartialViewList = homeModel.AllBoxViews(databaseRepository.PartialViews);
viewModel.maxNumberOfViews = viewModel.PartialViewList.Count();
return PartialView(viewModel);
}
[HttpPost]
public RedirectResult _PartialSettingsDropDownList1(PartialScreenViewModel viewModel)
{
for (int i = 0; i < viewModel.maxNumberOfViews; i++)
{
PartialView viewOnScreen = databaseRepository.PartialViews.FirstOrDefault(x => x.ID == viewModel.PartialViewList[i].ID);
databaseRepository.UpdatePartialView(viewOnScreen, i+1);
}
return new RedirectResult("Settings");
}
Model:
public List<PartialView> AllBoxViews(IEnumerable<PartialView> allViews)
{
List<PartialView> OnlyBoxViews = new List<PartialView>();
foreach (var item in allViews.Where(item => item.Type.Equals("box")))
{
OnlyBoxViews.Add(item);
}
return OnlyBoxViews;
}
ViewModel:
public class PartialScreenViewModel
{
public List<PartialView> PartialViewList { get; set; }
public int maxNumberOfViews { get; set; }
}
Result on screen: screenshot
I am building a two-level menu for my application using wicket framework. Using ListView#populateItem is redrawing the markup (SubMenuPanel.html) and unable to display menu items which were buried inside markup tags in SubMenuPanel.html. Code below -
html:
<div wicket:id="navMenu"></div>
Main.java:
NavigationMenu navigationMenu = new NavigationMenu("navMenu", navigationMenuAdapter);
add(navigationMenu);
NavigationMenu.java
public NavigationMenu(final String id, final NavigationMenuAdapter adapter)
{
super(id);
this.adapter = adapter;
add(new SubMenuPanel("mainMenu", adapter.getNavigationMenus(this)));
}
SubMenuPanel.java
public SubMenuPanel(final String id, List<NavigationMenuItem> list)
{
super(id);
add(new Rows("firstLevel", list));
setVersioned(false);
}
private static class Rows extends ListView<NavigationMenuItem>
{
private static final long serialVersionUID = 1L;
public Rows(String name, List<NavigationMenuItem> list)
{
super(name, list);
}
#Override
protected void populateItem(ListItem<NavigationMenuItem> listItem)
{
Object modelObject = listItem.getDefaultModelObject();
WebMarkupContainer rowAnchor = new WebMarkupContainer("firstLevelLink");
rowAnchor.add(new Label("firstLevelLabel", ((NavigationMenuItem) modelObject).getName()));
rowAnchor.add(new AttributeAppender("onclick", new Model("handleMenuClick()");
listItem.add(rowAnchor);
listItem.add(new SubMenuPanel("secondLevelMenu", ((NavigationMenuItem) modelObject).getChildMenuItem()));
}
}
SubMenuPanel.html
<body>
<wicket:panel>
<li wicket:id="firstLevel">
<a wicket:id="firstLevelLink" class="dropdown-toggle" aria-expanded="true" data-toggle="dropdown" href="javascript:void(0);" >
<span wicket:id="firstLevelLabel"></span>
</a>
<ul wicket:id="secondLevelMenu" class="dropdown-menu">
</ul>
</li>
</wicket:panel>
Working version
Non-working
I have added a Form on submit of which I have to add more wicket controls like Labels, textfields and button with an Ajex Link. But not able to get the correct HTML. Can anyone please help me to get rid of it ?
voucherPanel.html
<html xmlns:wicket>
<head>
</head>
<body>
<wicket:panel>
<div class="form-block">
<div wicket:id="form">
<wicket:message key="lbl.vouchercode" />
<div wicket:id="list">
<input wicket:id="word" type="text" />
</div>
<div wicket:id="vouchercode"></div>
<button wicket:id="submit"><wicket:message key="submitText"/></button>
</div>
</div>
</wicket:panel>
</body>
</html>
voucherPanel.java
public class VoucherPanel extends Panel
{
private static final long serialVersionUID = 1L;
public VoucherPanel(final String id)
{
super(id);
final TextField<String> voucherCodeField = new TextField<String>("vouchercode", Model.of(""));
voucherCodeField.setRequired(true);
final Button button = new Button("submit");
Form<?> form = new Form<Void>("form")
{
#Override
protected void onSubmit()
{
numberOfFields = new ArrayList<String>();
int noOfVocuhers = getNoOfAllowedVoucher();// just returing the number
for (int i = 0; i < noOfVocuhers; i++) {
numberOfFields.add(new String(""));
}
add(new ListView<Object>("list", numberOfFields) {
private static final long serialVersionUID = 1L;
#Override
protected void populateItem(ListItem<Object> item) {
final String word = (String) item.getModelObject();
System.out.println( "word =" +word );
TextField<String> textField = new TextField<String>("word", Model.of(""));
textField.setOutputMarkupId(true);
item.add(textField);
}
});
}
}
};
add(form);
form.add(voucherCodeField);
form.add(button);
}
}
You're trying to assign a Textfield to a <div> element (voucherCode), you need <input type="text"> instead.
You need to add list to your form right away, onSubmit is too late. Just set it outside, similar to button and call myListView.setList when submitting the form.
These are the two things I spotted... if you still have problems please let us know about the error messages you get.
I have built a wicket component that contains input/labels and methods to change presentation (required, enabled, etc.). The components render fine, but what happens is when the form submits I see only 1 form parameter 'input', and it's the last InputRow component.
InputRow.html
<html xmlns:wicket="http://wicket.apache.org">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<wicket:panel>
<label wicket:id="label">abc: <span class="req">*</span></label>
<span class="input">
<input wicket:id="input" type="text" id="name"></input>
</span>
<span wicket:id="input_feedback"></span>
</wicket:panel>
</body>
</html>
InputRow.java
package com.wicket;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
public class InputRow extends Panel{
#SuppressWarnings("unused")
private String id;
public InputRow(String id, String label) {
super(id);
this.id = id;
Label memberIdLabel = new Label("label",label);
memberIdLabel.setEscapeModelStrings(false)
.add(new AttributeAppender("for", new Model<String>(id),""));
add(memberIdLabel);
TextField<String> name = new TextField<String>("input");
name.setType(String.class)
.setMarkupId(id)
.setOutputMarkupId(true);
add(name);
add(new Label("input_feedback",""));
}
public InputRow disable()
{
get("input")
.setEnabled(false)
.add(new AttributeAppender("class", new Model<String>("disabled"),""));
get("label")
.add(new AttributeAppender("class", new Model<String>("disabled"),""));
return this;
}
public InputRow required()
{
Model model = (Model)get("label").getInnermostModel();
StringBuffer label = new StringBuffer((String)model.getObject());
label.append(" <span class=\"req\">*</span>");
model.setObject(label);
((TextField)get("input")).setRequired(true);
return this;
}
#Override
protected void onBeforeRender() {
super.onBeforeRender();
Label feedback = (Label)get("input_feedback");
if (get("input").getFeedbackMessage() != null)
{
feedback.setDefaultModel(new Model<String>("Required"));
}
}
}
Adding to the form component
add(new InputRow("name","Name:").required());
edit
I didn't set up a ListView or repeater since I know what rows / fields I want to add to the form at build time.
Your InputFields are missing their models. This way, wicket doesn't know where to store the formdata. If you add models to the fields they will be populated automatically.
There's not just one form parameter submitted. The submits are of the named like name:input, name2:input, ...
But as Nicktar suggests in the comment you should use a model to bind the value of the form component to your entity object. You have to accept an IModel in the constructor and use it in the constructor of TextField.
A better approach to what you are trying to do is to write a Behavior which adds decorating markup for your FormComponent. That way it works for more than just simple text input fields and you can fully customize the instances of your FormComponents.
It could look like this:
public class FormComponentBehavior extends Behavior {
#Override
public void bind(Component component) {
if (!(component instanceof FormComponent)) {
throw new IllegalArgumentException();
}
}
#Override
public void beforeRender(Component component) {
FormComponent<?> fc = (FormComponent<?>) component;
Response r = component.getResponse();
r.write("<label" + (fc.isRequired() ? " class='required'" : "") + ">");
r.write(fc.getLabel().getObject());
r.write("</label>");
r.write("<span class='input'>");
}
#Override
public void afterRender(Component component) {
component.getResponse().write("</span>");
// if feedback errors write them to markup...
}
}
Then you have to add this behavior to your FormComponent instances.
Maybe the problem with your form is that your input text fields have all the same id. Try using attribute 'name' instead of 'id'
I have some basic form when you type email, old password, new password and repeat new pass for your profile modify. What I'm trying to achive is to display feedback msg when pass is wrong. A piece of code looks like this:
public class EditProfileForm extends Form<Void>
{
private static final long serialVersionUID = 1L;
// El-cheapo model for form
private final ValueMap properties = new ValueMap();
private ModalWindow modalWindow;
#SpringBean
UserManager userManager;
#SpringBean
Validator validator;
private User user;
private static final String EMAIL = "mp-email";
private static final String OLD_PASS = "mp-oldpass";
private static final String NEW_PASS = "mp-newpass";
private static final String NEW_PASS_REPEAT = "mp-newpassrepeat";
private static final String ERROR_WRONG_PASS = "Wrong pass";
private static final String ERROR_PASS_DIFF = "Pass diff";
private static final String ERROR_EMAIL_INVALID = "Wrong email";
private static final String ERROR_EMAIL_EXISTS = "Email used";
public EditProfileForm( String id, final ModalWindow modalWindow,final User u )
{
super( id );
this.user = u;
this.modalWindow = modalWindow;
add( new TextField<String>( EMAIL, new PropertyModel<String>( properties, EMAIL ) ).setRequired(true).setOutputMarkupId(true) );
add( new PasswordTextField( OLD_PASS, new PropertyModel<String>( properties, OLD_PASS ) ).setOutputMarkupId(true) );
add( new PasswordTextField( NEW_PASS, new PropertyModel<String>( properties, NEW_PASS ) ).setOutputMarkupId(true) );
add( new PasswordTextField( NEW_PASS_REPEAT, new PropertyModel<String>( properties, NEW_PASS_REPEAT ) ).setOutputMarkupId(true) );
final FeedbackPanel feedbackPanel = new FeedbackPanel( "feedback" );
feedbackPanel.setOutputMarkupId( true );
//feedbackPanel.setMaxMessages( 5 );
add( feedbackPanel );
AjaxSubmitLink closeBtn = new AjaxCloseCancelBtn( "close-x", this );
AjaxSubmitLink cancelBtn = new AjaxCloseCancelBtn( "cancel", this );
add( new AjaxSubmitLink( "save", this )
{
private static final long serialVersionUID = 1L;
#Override
protected void onSubmit( AjaxRequestTarget target, Form<?> form )
{
if ( !user.getCryptedPassword().equals( CypherUtil.encodeMd5( getOldPassword() ) ) )
{
error( ERROR_WRONG_PASS );
}
else if ( !getNewPassword().equals( getNewPasswordRepeat() ) )
{
error( ERROR_PASS_DIFF );
}
else if ( !validator.validateEmailFormat( getEmail() ) )
{
error( ERROR_EMAIL_INVALID );
}
else if ( validator.emailExists( getEmail() ) )
{
error( ERROR_EMAIL_EXISTS );
} else
{
//save user data
}
}
#Override
protected void onError( AjaxRequestTarget target, Form<?> form )
{
target.add( feedbackPanel );
}
} );
add( closeBtn );
add( cancelBtn );
}
/**
* #return
*/
private String getEmail()
{
return properties.getString( EMAIL );
}
/**
* #return
*/
private String getOldPassword()
{
return properties.getString( OLD_PASS );
}
/**
* #return
*/
private String getNewPassword()
{
return properties.getString( NEW_PASS );
}
/**
* #return
*/
private String getNewPasswordRepeat()
{
return properties.getString( NEW_PASS_REPEAT );
}
}
Now when I leave these forms empty, I receive nice feedback msg that there fields are required. Meanwhile, when I type wrong pass, email or whatever I got nothing, and my server log leaves msg like this:
WARNING: Component-targetted feedback message was left unrendered.
This could be because you are missing a FeedbackPanel on the page.
Message: [FeedbackMessage message = "Wrong pass", reporter = save, level = ERROR]
The form is within a WebPage which is a popup:
public class ProfilePopup extends WebPage
{
private static final long serialVersionUID = 2929269801026361184L;
public ProfilePopup(final ModalWindow modal, final User user)
{
add( new EditProfileForm("profileModifyForm", modal, user).setOutputMarkupId(true) );
}
}
and HTML, placing feedback outside the form didn't help either :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body class="stats-popup-body">
<div class="stats-popup" id="car-info-edit-popup">
<p class="popup_title"> Edytuj Profilu </p>
<form wicket:id="profileModifyForm" class="stats-popup-form">
<div>
<label class="popup_field_label">Email:</label>
<input type="text" wicket:id="mp-email" />
</div>
<div class="clear9"></div>
<div>
<label class="popup_field_label">Stare hasło:</label>
<input type="password" name="E-mail" title="E-mail1" id="E-mail2" wicket:id="mp-oldpass" />
</div>
<div>
<label class="popup_field_label">Nowe hasło:</label>
<input type="password" wicket:id="mp-newpass" />
</div>
<div>
<label class="popup_field_label">Powtórz nowe hasło:</label>
<input type="password" wicket:id="mp-newpassrepeat" />
</div>
<span wicket:id="feedback"></span>
<div class="button-box-bottom">
<input class="btn btn_save" style="margin-right: 9px;"
wicket:id="save" type="button" value="Zapisz"
onmousemove="this.className='btn btn_save btn_hover'"
onmouseout="this.className='btn btn_save'" />
<input
class="btn btn_cancel" wicket:id="cancel"
value="Anuluj" type="button"
onmousemove="this.className='btn btn_cancel btn_hover'"
onmouseout="this.className='btn btn_cancel'" />
</div>
<div class="stats-popup-close-x" wicket:id="close-x"></div>
</form>
</div>
</body>
</html>
It's bad practice to perform input validations in onSubmit, because once you get there, (invalid) input has reached the Models. As you already are experiencing, onSubmit is invoked after the validation phase has ended, so the input will be considered valid, and therefore Form.onError will not be invoked.
Use a FormValidator instead (add an IFormValidator to the Form in your constructor), if you require to perform not so simple validations or validations that involve two or more components' inputs. Remember that user input will have not reached the component's Models in FormValidator.validate(), so you'll need to use Component.getConvertedInput() to get the input to be validated.
If your validations involve only one component, and operate only over its input, it might be recommendable to use an IValidator instead.
Also, notice that Wicket provides validators that perform some of the validations you'd like to perform: EqualPasswordInputValidator and EmailAddressValidator can be useful to you.
For instance:
emailField.add(EmailAddressValidator.getInstance());
form.add(new EqualPasswordInputValidator(passwordField, passwordRepeatField));
Take a look at this (somewhat outdated) wiki page for information on FormValidators: Validating related fields