Java Code Examples for org.apache.wicket.markup.html.form.Form#getModelObject()

The following examples show how to use org.apache.wicket.markup.html.form.Form#getModelObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MySocialNetworkingEdit.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private boolean save(Form form) {
	
	// get the backing model
	UserProfile userProfile = (UserProfile) form.getModelObject();
	
	// save social networking information
	SocialNetworkingInfo socialNetworkingInfo = new SocialNetworkingInfo(userProfile.getUserUuid());
	
	String tFacebook = ProfileUtils.truncate(userProfile.getSocialInfo().getFacebookUrl(), 255, false);
	String tLinkedin = ProfileUtils.truncate(userProfile.getSocialInfo().getLinkedinUrl(), 255, false);
	String tMyspace = ProfileUtils.truncate(userProfile.getSocialInfo().getMyspaceUrl(), 255, false);
	String tSkype = ProfileUtils.truncate(userProfile.getSocialInfo().getSkypeUsername(), 255, false);
	String tTwitter = ProfileUtils.truncate(userProfile.getSocialInfo().getTwitterUrl(), 255, false);

	socialNetworkingInfo.setFacebookUrl(tFacebook);
	socialNetworkingInfo.setLinkedinUrl(tLinkedin);
	socialNetworkingInfo.setMyspaceUrl(tMyspace);
	socialNetworkingInfo.setSkypeUsername(tSkype);
	socialNetworkingInfo.setTwitterUrl(tTwitter);
	
	return profileLogic.saveSocialNetworkingInfo(socialNetworkingInfo);
	
}
 
Example 2
Source File: MyInterestsEdit.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private boolean save(Form form) {
	
	//get the backing model
	UserProfile userProfile = (UserProfile) form.getModelObject();
	
	//get userId from the UserProfile (because admin could be editing), then get existing SakaiPerson for that userId
	String userId = userProfile.getUserUuid();
	SakaiPerson sakaiPerson = sakaiProxy.getSakaiPerson(userId);
	
	//get values and set into SakaiPerson
	sakaiPerson.setFavouriteBooks(userProfile.getFavouriteBooks());
	sakaiPerson.setFavouriteTvShows(userProfile.getFavouriteTvShows());
	sakaiPerson.setFavouriteMovies(userProfile.getFavouriteMovies());
	sakaiPerson.setFavouriteQuotes(userProfile.getFavouriteQuotes());

	//update SakaiPerson
	if(profileLogic.saveUserProfile(sakaiPerson)) {
		log.info("Saved SakaiPerson for: " + userId );
		return true;
	} else {
		log.info("Couldn't save SakaiPerson for: " + userId);
		return false;
	}
}
 
Example 3
Source File: MyStudentEdit.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private boolean save(Form form) {

		//get the backing model
		UserProfile userProfile = (UserProfile) form.getModelObject();
		
		SakaiPerson sakaiPerson = sakaiProxy.getSakaiPerson(userProfile.getUserUuid());
		sakaiPerson.setEducationCourse(userProfile.getCourse());
		sakaiPerson.setEducationSubjects(userProfile.getSubjects());
		
		//update SakaiPerson
		if(profileLogic.saveUserProfile(sakaiPerson)) {
			log.info("Saved SakaiPerson for: " + userProfile.getUserUuid() );
			return true;
		} else {
			log.info("Couldn't save SakaiPerson for: " + userProfile.getUserUuid());
			return false;
		}
	
	}
 
Example 4
Source File: MyNamePronunciationEdit.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private boolean save(Form form) {
    //get the backing model
    UserProfile userProfile = (UserProfile) form.getModelObject();

    //get userId from the UserProfile (because admin could be editing), then get existing SakaiPerson for that userId
    String userId = userProfile.getUserUuid();
    SakaiPerson sakaiPerson = sakaiProxy.getSakaiPerson(userId);

    sakaiPerson.setPhoneticPronunciation(userProfile.getPhoneticPronunciation());
    if (audioBase64.getDefaultModelObject() != null) {
        String audioStr = audioBase64.getDefaultModelObject().toString().split(",")[1];
        String path = profileLogic.getUserNamePronunciationResourceId(userId);
        byte[] bytes = Base64.getDecoder().decode(audioStr.getBytes(StandardCharsets.UTF_8));
        sakaiProxy.removeResource(path);
        sakaiProxy.saveFile(path, userId, userId+".wav", "audio/wav", bytes);
    }

    if(profileLogic.saveUserProfile(sakaiPerson)) {
        log.info("Saved SakaiPerson for: " + userId );
        return true;
    } else {
        log.info("Couldn't save SakaiPerson for: " + userId);
        return false;
    }
}
 
Example 5
Source File: ConfirmationDialog.java    From webanno with Apache License 2.0 6 votes vote down vote up
protected void onConfirmInternal(AjaxRequestTarget aTarget, Form<State> aForm)
{
    State state = aForm.getModelObject();
    
    boolean closeOk = true;
    
    // Invoke callback if one is defined
    if (confirmAction != null) {
        try {
            confirmAction.accept(aTarget);
        }
        catch (Exception e) {
            LoggerFactory.getLogger(getPage().getClass()).error("Error: " + e.getMessage(), e);
            state.feedback = "Error: " + e.getMessage();
            aTarget.add(aForm);
            closeOk = false;
        }
    }
    
    if (closeOk) {
        close(aTarget);
    }
}
 
Example 6
Source File: KeyBindingsConfigurationPanel.java    From webanno with Apache License 2.0 6 votes vote down vote up
private void addKeyBinding(AjaxRequestTarget aTarget, Form<KeyBinding> aForm)
{
    KeyBinding keyBinding = aForm.getModelObject();
    
    if (StringUtils.isBlank(keyBinding.getKeyCombo())) {
        error("Key combo is required");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    
    // Copy value from the value editor over into the form model (key binding) and then add it
    // to the list
    AnnotationFeature feature = getModelObject();
    FeatureSupport<?> fs = featureSupportRegistry.getFeatureSupport(feature);
    keyBinding.setValue(fs.unwrapFeatureValue(feature, null, featureState.getObject().value));
    keyBindings.getObject().add(keyBinding);
    
    // Clear form and value editor
    aForm.setModelObject(new KeyBinding());
    featureState.getObject().setValue(null);
    
    success("Key binding added. Do not forget to save the feature details!");
    aTarget.addChildren(getPage(), IFeedback.class);
    aTarget.add(keyBindingsContainer);
}
 
Example 7
Source File: BulkEditItemsPanel.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {

	final List<Assignment> assignments = (List<Assignment>) form.getModelObject();

	boolean result = false;
	for (final Assignment a : assignments) {

		log.debug("Bulk edit assignment: {}", a);
		result = BulkEditItemsPanel.this.businessService.updateAssignment(a);
	}
	for (int count=0; count < BulkEditItemsPanel.this.getDeletableItemsList().size(); count++){
		BulkEditItemsPanel.this.businessService.removeAssignment(BulkEditItemsPanel.this.getDeletableItemsList().get(count));
	}
	BulkEditItemsPanel.this.clearDeletableItemsList();
	if (result) {
		getSession().success(getString("bulkedit.update.success"));
	} else {
		getSession().error(getString("bulkedit.update.error"));
	}
	setResponsePage(GradebookPage.class);
}
 
Example 8
Source File: StatementEditor.java    From inception with Apache License 2.0 6 votes vote down vote up
private void actionSave(AjaxRequestTarget aTarget, Form<KBStatement> aForm)
{
    KBStatement modifiedStatement = aForm.getModelObject();

    if (modifiedStatement.getValue() == null) {
        error("The value of statement cannot be empty");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }

    try {
        // persist the modified statement and replace the original, unchanged model
        KBStatement oldStatement = statement.getObject();
        kbService.upsertStatement(kbModel.getObject(), modifiedStatement);
        statement.setObject(modifiedStatement);
        // switch back to ViewMode and send notification to listeners
        actionCancelExistingStatement(aTarget);
        send(getPage(), Broadcast.BREADTH,
                new AjaxStatementChangedEvent(aTarget, statement.getObject(), oldStatement));
    }
    catch (RepositoryException e) {
        error("Unable to update statement: " + e.getLocalizedMessage());
        LOG.error("Unable to update statement.", e);
        aTarget.addChildren(getPage(), IFeedback.class);
    }
}
 
Example 9
Source File: ColoringRulesConfigurationPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
private void addColoringRule(AjaxRequestTarget aTarget, Form<ColoringRule> aForm)
{
    ColoringRule coloringRule = aForm.getModelObject();
    
    if (isBlank(coloringRule.getColor())) {
        error("Color is required");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }

    if (isBlank(coloringRule.getPattern())) {
        error("Pattern is required");
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }

    try {
        Pattern.compile(coloringRule.getPattern());
    }
    catch (PatternSyntaxException e) {
        error("Pattern is not a valid regular expression: " + e.getMessage());
        aTarget.addChildren(getPage(), IFeedback.class);
        return;
    }
    
    coloringRules.getObject().add(coloringRule);
    
    aForm.setModelObject(new ColoringRule());
    
    success("Coloring rule added. Do not forget to save the layer details!");
    aTarget.addChildren(getPage(), IFeedback.class);
    aTarget.add(coloringRulesContainer);
}
 
Example 10
Source File: ProjectDetailPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
private void actionSave(AjaxRequestTarget aTarget, Form<Project> aForm)
{
    aTarget.add(getPage());
    // aTarget.add(((ApplicationPageBase) getPage()).getPageContent());
    // aTarget.addChildren(getPage(), IFeedback.class);
    
    Project project = aForm.getModelObject();
    if (isNull(project.getId())) {
        try {
            String username = SecurityContextHolder.getContext().getAuthentication().getName();
            projectService.createProject(project);

            projectService.createProjectPermission(
                    new ProjectPermission(project, username, PermissionLevel.MANAGER));
            projectService.createProjectPermission(
                    new ProjectPermission(project, username, PermissionLevel.CURATOR));
            projectService.createProjectPermission(
                    new ProjectPermission(project, username, PermissionLevel.ANNOTATOR));

            projectService.initializeProject(project);
        }
        catch (IOException e) {
            error("Project repository path not found " + ":"
                    + ExceptionUtils.getRootCauseMessage(e));
            LOG.error("Project repository path not found " + ":"
                    + ExceptionUtils.getRootCauseMessage(e));
        }
    }
    else {
        projectService.updateProject(project);
    }

    Session.get().setMetaData(CURRENT_PROJECT, project);
}
 
Example 11
Source File: MergeDialog.java    From webanno with Apache License 2.0 5 votes vote down vote up
protected void onConfirmInternal(AjaxRequestTarget aTarget, Form<State> aForm)
{
    State state = aForm.getModelObject();
    
    // Check if the challenge was met
    if (!ObjectUtils.equals(state.expectedResponse, state.response)) {
        state.feedback = "Your response did not meet the challenge.";
        aTarget.add(aForm);
        return;
    }
    
    boolean closeOk = true;
    
    // Invoke callback if one is defined
    if (confirmAction != null) {
        try {
            confirmAction.accept(aTarget, aForm);
        }
        catch (Exception e) {
            LoggerFactory.getLogger(getPage().getClass()).error("Error: " + e.getMessage(), e);
            state.feedback = "Error: " + e.getMessage();
            aTarget.add(aForm);
            closeOk = false;
        }
    }
    
    if (closeOk) {
        close(aTarget);
    }
}
 
Example 12
Source File: ViewWallPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean save(Form form, String userUuid) {
	
	WallItem wallItem = (WallItem) form.getModelObject();
	wallItem.setDate(new Date());
	
	return wallLogic.postWallItemToWall(userUuid, wallItem);
}
 
Example 13
Source File: MyStaffEdit.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private boolean save(Form form) {
	
	//get the backing model
	UserProfile userProfile = (UserProfile) form.getModelObject();
	
	//get userId from the UserProfile (because admin could be editing), then get existing SakaiPerson for that userId
	
	String userId = userProfile.getUserUuid();
	SakaiPerson sakaiPerson = sakaiProxy.getSakaiPerson(userId);

	String tDepartment = ProfileUtils.truncate(userProfile.getDepartment(), 255, false);
	String tPosition = ProfileUtils.truncate(userProfile.getPosition(), 255, false);
	String tSchool = ProfileUtils.truncate(userProfile.getSchool(), 255, false);
	String tRoom = ProfileUtils.truncate(userProfile.getRoom(), 255, false);
	
	//get values and set into SakaiPerson
	sakaiPerson.setOrganizationalUnit(tDepartment);
	sakaiPerson.setTitle(tPosition);
	sakaiPerson.setCampus(tSchool);
	sakaiPerson.setRoomNumber(tRoom);
	sakaiPerson.setStaffProfile(userProfile.getStaffProfile());
	sakaiPerson.setUniversityProfileUrl(userProfile.getUniversityProfileUrl());
	sakaiPerson.setAcademicProfileUrl(userProfile.getAcademicProfileUrl());
	
	//PRFL-467 store as given, and process when it is retrieved.
	sakaiPerson.setPublications(userProfile.getPublications());
	
	//update SakaiPerson
	if(profileLogic.saveUserProfile(sakaiPerson)) {
		log.info("Saved SakaiPerson for: " + userId );
		return true;
	} else {
		log.info("Couldn't save SakaiPerson for: " + userId);
		return false;
	}
}
 
Example 14
Source File: MyPrivacy.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private boolean save(Form<ProfilePrivacy> form) {
	
	//get the backing model - its elems have been updated with the form params
	ProfilePrivacy profilePrivacy = (ProfilePrivacy) form.getModelObject();

	if(privacyLogic.savePrivacyRecord(profilePrivacy)) {
		log.info("Saved ProfilePrivacy for: " + profilePrivacy.getUserUuid());
		return true;
	} else {
		log.info("Couldn't save ProfilePrivacy for: " + profilePrivacy.getUserUuid());
		return false;
	}

}
 
Example 15
Source File: QualifierEditor.java    From inception with Apache License 2.0 5 votes vote down vote up
private void actionSave(AjaxRequestTarget aTarget, Form<KBQualifier> aForm) {
    KBQualifier modifiedQualifier = aForm.getModelObject();
    kbService.upsertQualifier(kbModel.getObject(), modifiedQualifier);
    qualifier.setObject(modifiedQualifier);

    actionCancelExistingQualifier(aTarget);
}
 
Example 16
Source File: MyWallPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private boolean save(Form form, String userUuid) {
	
	WallItem wallItem = (WallItem) form.getModelObject();
	wallItem.setDate(new Date());
	
	return wallLogic.postWallItemToWall(userUuid, wallItem);
}
 
Example 17
Source File: GeneralSettingsPanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
protected void afterChange(Form form, AjaxRequestTarget target) {	
   	Settings settings = (Settings)form.getModelObject();    		
   	if (!oldReportsHome.equals(settings.getReportsHome())) {
   		// add new reports home to classpath
   		try {
			addURL(new File(settings.getReportsHome()).toURI().toURL());			
		} catch (Exception e) {				
			e.printStackTrace();
		}
   	}    	
}
 
Example 18
Source File: GeneralSettingsPanel.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
protected void beforeChange(Form form, AjaxRequestTarget target) {	
   	Settings settings = (Settings)form.getModelObject();
   	if (settings.getReportsUrl().endsWith("/")) {
   		settings.setReportsUrl(settings.getReportsUrl().substring(0, settings.getReportsUrl().length()-1));
   	}
}
 
Example 19
Source File: MyInfoEdit.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private boolean save(Form form) {
	

	//get the backing model
	UserProfile userProfile = (UserProfile) form.getModelObject();
	
	//get userId from the UserProfile (because admin could be editing), then get existing SakaiPerson for that userId
	String userId = userProfile.getUserUuid();
	SakaiPerson sakaiPerson = sakaiProxy.getSakaiPerson(userId);

	//set the attributes from userProfile that this form dealt with, into sakaiPerson
	//this WILL fail if there is no sakaiPerson for the user however this should have been caught already
	//as a new Sakaiperson for a user is created in MyProfile.java if they don't have one.
	
	//TODO should we set these up as strings and clean them first?
	
	//sakaiPerson.setInitials(userProfile.getMiddleName());
	String tNickname = ProfileUtils.truncate(userProfile.getNickname(), 255, false);
	userProfile.setNickname(tNickname); //update form model
	sakaiPerson.setNickname(tNickname);
	
	if(StringUtils.isNotBlank(userProfile.getBirthday())) {
		Date convertedDate = ProfileUtils.convertStringToDate(userProfile.getBirthday(), ProfileConstants.DEFAULT_DATE_FORMAT);
		userProfile.setDateOfBirth(convertedDate); //set in userProfile which backs the profile
		sakaiPerson.setDateOfBirth(convertedDate); //set into sakaiPerson to be persisted to DB
	} else {
		userProfile.setDateOfBirth(null); //clear both fields
		sakaiPerson.setDateOfBirth(null);
	}

	//PRFL-467 store as given, and process when it is retrieved.
	sakaiPerson.setNotes(userProfile.getPersonalSummary());
	
	if(profileLogic.saveUserProfile(sakaiPerson)) {
		log.info("Saved SakaiPerson for: " + userId);
		
		//update their name details in their account if allowed
		/*
		if(sakaiProxy.isAccountUpdateAllowed(userId)) {
			sakaiProxy.updateNameForUser(userId, userProfile.getFirstName(), userProfile.getLastName());
		
			//now update displayName in UserProfile
			userProfile.setDisplayName(sakaiProxy.getUserDisplayName(userId));
		
		}
		*/
		
		return true;
	} else {
		log.info("Couldn't save SakaiPerson for: " + userId);
		return false;
	}
}
 
Example 20
Source File: MyInfoEdit.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private boolean save(Form form) {
	

	//get the backing model
	UserProfile userProfile = (UserProfile) form.getModelObject();
	
	//get userId from the UserProfile (because admin could be editing), then get existing SakaiPerson for that userId
	String userId = userProfile.getUserUuid();
	SakaiPerson sakaiPerson = sakaiProxy.getSakaiPerson(userId);

	//set the attributes from userProfile that this form dealt with, into sakaiPerson
	//this WILL fail if there is no sakaiPerson for the user however this should have been caught already
	//as a new Sakaiperson for a user is created in MyProfile.java if they don't have one.
	
	//TODO should we set these up as strings and clean them first?
	
	//sakaiPerson.setInitials(userProfile.getMiddleName());
	String tNickname = ProfileUtils.truncate(userProfile.getNickname(), 255, false);
	userProfile.setNickname(tNickname); //update form model
	sakaiPerson.setNickname(tNickname);
	
	if(StringUtils.isNotBlank(userProfile.getBirthday())) {
		Date convertedDate = ProfileUtils.convertStringToDate(userProfile.getBirthday(), ProfileConstants.DEFAULT_DATE_FORMAT);
		userProfile.setDateOfBirth(convertedDate); //set in userProfile which backs the profile
		sakaiPerson.setDateOfBirth(convertedDate); //set into sakaiPerson to be persisted to DB
	} else {
		userProfile.setDateOfBirth(null); //clear both fields
		sakaiPerson.setDateOfBirth(null);
	}

	//PRFL-467 store as given, and process when it is retrieved.
	sakaiPerson.setNotes(userProfile.getPersonalSummary());
	
	if(profileLogic.saveUserProfile(sakaiPerson)) {
		log.info("Saved SakaiPerson for: " + userId);
		
		//update their name details in their account if allowed
		/*
		if(sakaiProxy.isAccountUpdateAllowed(userId)) {
			sakaiProxy.updateNameForUser(userId, userProfile.getFirstName(), userProfile.getLastName());
		
			//now update displayName in UserProfile
			userProfile.setDisplayName(sakaiProxy.getUserDisplayName(userId));
		
		}
		*/
		
		return true;
	} else {
		log.info("Couldn't save SakaiPerson for: " + userId);
		return false;
	}
}